import * as echarts from 'echarts'
import { ref } from 'vue'

export default function initChartLine(id) {
  const myChartLine = ref(null)

  /**
   * 渲染折线图
   */
  const rednerLine = ({ xData, seriesData, seriesData1, El }) => {
    myChartLine.value = echarts.init(El)
    const option = {
      grid: {
        top: 40,
        left: 30,
        right: 15,
        bottom: 50
      },
      tooltip: {
        show: true,
        trigger: 'axis'
      },
      xAxis: {
        type: 'category',
        data: xData
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          name: '计划工作完成量',
          data: seriesData,
          type: 'line'
        },
        {
          name: '实际工作完成量',
          data: seriesData1,
          type: 'line'
        }
      ]
    }
    option && myChartLine.value.setOption(option)
  }

  return {
    myChartLine,
    rednerLine
  }
}
